GitHub

您所在的位置:网站首页 micropython ota GitHub

GitHub

2023-12-17 07:24| 来源: 网络整理| 查看: 265

MicroPython OTA Update

This is a modified version of micropython-ota-updater to work with MicroPython v1.13 and devices with lower memory.

I wrote this for the ESP8622, but it should definitely work with the ESP32 or any chips with RAM equal to or greater than the ESP8622.

Features Works for MicroPython v1.13 Only updates scripts in the directory specified (e.g. /project) ToDo Be able to revert to the previous version Be able to download a specific version Failsafes If no version exists - download the last stable version If the device powers off mid update, revert to previous Usage Helpful Params Param Description tgt_dir The directory containing the code you want auto-updated wifi_ssd The WiFi network name wifi_pass The WiFi network pass github_url The URL to the GitHub repository the updates are downloaded from TLDR Usage Specify the Params (see Setup & Prerequisites section) Call ota_check() in main.py to check for new updates Call ota_install() in main.py to download and install updates Reboot the device Setup & Prerequisites

Make sure these steps are completed before you run the OTA.

Set Credentials

Specify the required credentials including:

WiFi SSID & password GitHub repo to update from

These credentials are currently in main.py.

If the chip is already connected to WiFi that step can be skipped - or ignored if you already have a WiFi script you prefer to use. Just be sure to check for a WiFi connection before running the OTA.

The GitHub repo needs to be set to the repository the updates will be downloaded from. The repository must have the tgt_dir specified above as that is the data that will be downloaded.

Use Tags to Specify the Latest Release

You must specify a 'latest' version in GitHub. The code will query GitHub for the latest repo release and if the release is newer than what is installed it will download the update.

You must use semantic versioning for this (e.g. 1.0.0). Below is a quick review of how to do this:

In Git specify the version and number: git tag -a "v1.0.0" -m "beta" Push the version number: git push origin master --tags Login to GitHub and Publish the release Click on the 'Tags' link Click the version you want to publish Click the 'Edit tag' button Click 'Publish release'

You can view the current version with git describe.

Logic

Below is how the script works.

Checking for Updates Call the OTACheck class and pass in the following arguments 'github_url' - This the URL to the repository you want to download updates from 'tgt_dir' - This is the directory that contains the updated code Query GitHub for the latest repo version If the version is newer than what is on the device Create a /next/ directory and save the newest version ID in /next/.version_on_reboot Exit OTA Download & Install Logic Check to see if a /next/.version_on_reboot file exists Open the file and get the version number saved Query GitHub to get the files for that version number Download all the files into the /next/ directory Rename the /next/.version_on_reboot file to /next/.version Rename /next/ directory to the 'tgt_dir' value Note: You will need to reboot the device machine.reboot() to apply the updates, but this has not been added to the code yet. Debugging Moving Files

Run import move_files in REPL to move and delete the specified files. This is due to a bug with PyCharm renaming all files inside sub-directories and moving them to /root.

Re-test Download | REPL

Run the following to convince the script to re-download the GitHub files.

import os os.mkdir('next') os.rename('/project/.version', '/next/.version_on_reboot')


【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3